package cn.yunhe.servlet;

import cn.yunhe.bean.Hotel;
import cn.yunhe.bean.RoomType;
import cn.yunhe.biz.RoomTypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/RoomServlet")
public class RoomServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String  s =request.getParameter("hotelid");
        int hotelid=0;

        if(s==null){
            hotelid = (int)session.getAttribute("hotelid");
        }else{
            hotelid =Integer.parseInt(s) ;
        }
        session.setAttribute("hotelid",hotelid);
        RoomTypeService roomTypeService =new RoomTypeService();
        Hotel hotel = roomTypeService.getAllIfo(hotelid);
        request.setAttribute("hotel",hotel);

        if(hotel!=null){
            request.getRequestDispatcher("getHotelCommentServlet").forward(request,response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
